﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace blackhouse.Web
{

    public class BaseFactory<T> where T : class
    {

        #region Instance

        private static T itsInstance = null;

        protected static T Instance(string factoryName)
        {
            if (itsInstance == null)
            {
                string factoryAss = System.Configuration.ConfigurationManager.AppSettings[factoryName];
                try
                {
                    itsInstance = System.Activator.CreateInstance(Type.GetType(factoryAss, true)) as T;
                    if (itsInstance == null)
                        throw new Exception();
                }
                catch (Exception exc)
                {
                    throw new Exception("Nie udało się utworzyć fabryki dla " + factoryName, exc);
                }
            }
            return itsInstance;
        }

        #endregion

    }
}